package com.binguo.model.mapper;

import com.binguo.model.core.Mapper;
import com.binguo.model.model.PayCard;
import com.binguo.model.mybatis.DomainExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

public interface PayCardMapper extends Mapper<PayCard> {
    PayCard selectPayCard(Integer shopID,Integer customerID ,Byte deleted);

    List<PayCard> getShopCard(Integer customerID);

    @Select("select * from pay_card where cardNo = #{cardNo}")
    PayCard selectPayCardByCardNo(String cardNo);



    /**
     */
    @Select("<script> \n " +
            " SELECT customerId  " +
            " FROM pay_card" +
            " where deleted = 0 " +
            " <if test='domain.shopid != null'> and shopId = '${domain.shopid}' </if> " +
            " <if test='domain.cardtype != null'> and cardType = '${domain.cardtype}' </if> " +
            " order by id desc " +
            " <if test='null != addition'> " +
            " limit #{addition.offset}, #{addition.limit} " +
            " </if> " +
            " </script> ")
    List<Integer> findCustomerIdList(DomainExample<PayCard> example);

    /**
     * 角色基本查询数量
     */
    @Select("<script> \n" +
            " SELECT count(*)  " +
            " FROM pay_card " +
            " where deleted = 0 " +
            " <if test='domain.shopid != null'> and shopId = '${domain.shopid}' </if> " +
            " <if test='domain.cardtype != null'> and cardType = '${domain.cardtype}' </if> " +
            " </script>"
    )
    Integer findCustomerIdCount(DomainExample<PayCard> example);

    Integer updatePayCardByCustomer(@Param("customerIDList") List customerIDList,
                                    @Param("rechargeMoney") Integer rechargeMoney,
                                    @Param("shopID") Integer shopID);

    Integer clearPayCardByCustomer(@Param("customerIDList") List customerIDList,
                                   @Param("shopID") Integer shopID);


    List<Integer> getCustomerIDListByGroupID(@Param("shopID") Integer shopID,
                                             @Param("groupID") Integer groupID);

    List<PayCard> getPayCardListByGroupID(@Param("shopID") Integer shopID,
                                          @Param("customerIDList") List customerIDList);

    List<PayCard> getUpdatePaycardList(@Param("shopID") Integer shopID,
                                       @Param("limit") Integer limit);

    @Select("select customerId as customerId ,pay_code_time as payCodeTime  from pay_card where pay_code = #{payCode}")
    PayCard selectByPayCode(@Param("payCode") String payCode);

}